/**
 * 
 */
package com.manthano.util.file;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

/**
 * @author DELL
 */
public class FileReaderWriterFactory
{
	/**
	 * @param fileType
	 * @param inputStream
	 * @param charset
	 * @return FileReader to read file
	 * @throws IOException
	 */
	public static FileReader getFileReader(FileType fileType, InputStream inputStream, String charset)
			throws IOException
	{
		FileReader fileReader = null;

		if (fileType.equals(FileType.TYPE_CSV))
		{
			fileReader = new CSVFileReader(inputStream, charset);
		}
		else if (fileType.equals(FileType.TYPE_XLS) || fileType.equals(FileType.TYPE_XLSX))
		{
			fileReader = new XLSXFileReader(inputStream);
		}
		else
		{
			throw new IOException("File Reader doesnt support this extensions");
		}
		return fileReader;

	}

	/**
	 * @param fileType
	 * @param outputStream
	 * @return FileWriter to write the file
	 * @throws IOException
	 */
	public static FileWriter getFileWriter(FileType fileType, OutputStream outputStream) throws IOException
	{
		FileWriter fileWriter = null;
		if (fileType.equals(FileType.TYPE_XLSX) || fileType.equals(FileType.TYPE_XLS))
		{
			fileWriter = new XLSXFileWriter(outputStream);
		}
		else if (fileType.equals(FileType.TYPE_CSV))
		{
			// TODO:
		}
		else
		{
			throw new IOException("File Writer doesn't support this extensions");
		}

		return fileWriter;
	}
}
